//Monday, November 16 2009
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class NextNumber
{
public:
	int getNextNumber(int N)
	{
		int sz = getweight(N);
		for(long long i=N+1; ; i++)
			if(getweight(i) == sz)
				return i;
	}
	int getweight(int n)
	{
		int ret = 0;
		while(n > 0)
		{
			if(n%2 == 1)
				ret++;
			n /= 2;
		}
		return ret;
	}
};
